package com.mooc.fileServlet;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.sql.DataSource;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class JdbcUtil {
	 //获取池对象
	 private static DataSource ds=new ComboPooledDataSource();
	 //获取连接
	 public static Connection getCon(){
		 try {
			 return ds.getConnection();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	 }
	 //归还连接
	 public static void release(ResultSet set,Statement sta,Connection con){
		 try{
			  if(set!=null){set.close();}
			  if(sta!=null){sta.close();}
			  if(con!=null){con.close();}
		 }catch (Exception e) {
			 throw new RuntimeException(e);
		}
	 }
     public static void main(String[] args) {
		   System.out.println(getCon());
	 }
}
